package base.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class 条件爬取 {
    public static void main(String[] args) {
        String s1 = "java,java4,java8,java11,java17";
        String regex1 = "java(?=8|11)";
        String regex2 = "java(?:8)";
        String regex3 = "java(?!8)\\w{0,2}";

        Pattern pattern = Pattern.compile(regex3);
        Matcher matcher = pattern.matcher(s1);
        while (matcher.find()){
            System.out.println(matcher.group());
        }


        //贪婪和非贪婪爬取
        String s2 = "abbbbbbbbbbaaabbbb";
        String regex4 = "ab+";
        String regex5 = "ab+?";

        Pattern p = Pattern.compile(regex5);
        Matcher m = p.matcher(s2);
        while (m.find()){
            System.out.println(m.group());
        }

    }
}
